package E2014;

import javax.swing.*;
import java.awt.*;

import static java.awt.BorderLayout.CENTER;

public class Exam2 {
    public void createAndShow(){
        JFrame frame = new JFrame();
        frame.setSize(500,300);
        frame.setLocation(500,500);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setLayout(new BorderLayout());
        frame.setVisible(true);

        JMenuBar menuBar = new JMenuBar();
        JMenu menu = new JMenu("文件");
        JMenuItem item1 = new JMenuItem("新建");
        JMenuItem item2 = new JMenuItem("打开");
        JMenuItem item3 = new JMenuItem("关闭");
        JMenuItem item4 = new JMenuItem("退出");

        menu.add(item1);
        menu.add(item2);
        menu.add(item3);
        menu.addSeparator();
        menu.add(item4);
        menuBar.add(menu);
        frame.setJMenuBar(menuBar);
    }
    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                Exam2 e = new Exam2();
                e.createAndShow();
            }
        });
    }
}
